import "./index.css";
import React, { useContext } from "react";
import TestContext from "../../utils";
import MyTestOne from "../MyTestOne";                                                                                

const MyTestTwo: React.FC = () => {
  const { testNum, setTestNum } = useContext(TestContext);

  //点击改变context的值
  const handleClick = () => {
    setTestNum(testNum + 1);
  };

  return (
    <>
      <div>
        这是我都测试context上下文的第二给组件---{testNum}
        ----使用usecontext传递过来的值
      </div>
      <button onClick={handleClick}>点击我改变上下文的值</button>
      <TestContext.Provider value={{testNum, setTestNum}}>
          <MyTestOne />
        </TestContext.Provider>
    </>
  );
};

export default MyTestTwo;
